<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../jquery-3.3.1.min.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        
        #top {
            width: 80px;
            height: 80px;
            background-color: red;
            position: fixed;
            _position: absolute;
            right: 60px;
            top: 0px;
            text-align: center;
            line-height: 80px;
            font-size: 20px;
            display: none;
        }
        
        .header {
            width: 100%;
            height: 60px;
            background-color: red;
            text-align: center;
            font-size: 40px;
        }
        
        .contain {
            width: 80%;
            height: 2500px;
            margin: 0 auto;
            background-color: yellowgreen;
            text-align: center;
            font-size: 40px;
        }
    </style>
</head>

<body>
    <div id="top">
        <span>返回顶部</span>
    </div>
    <div class="header">
        导航栏
    </div>
    <div class="contain">
        内容区域
    </div>
    <script>
        var t = document.documentElement.scrollTop || document.body.scrollTop;
        var bheight = document.documentElement.clientHeight || document.body.clientHeight;
        window.onscroll = window.onresize = window.onload = function() {
            $("#top").css("top", (bheight - 80) / 2 + "px");;
            t = document.documentElement.scrollTop || document.body.scrollTop;
            if (t > 800) {
                $("#top").css("display", "block");
            } else {
                $("#top").css("display", "none");
            }
        }
        $("#top").click(function() {
            $("html,body").animate({
                scrollTop: 0
            }, 500);
            //var id = setInterval("move", 100);
            //if (t == 800) {
            //    clearInterval(id);
            //}
        });
    </script>
</body>

</html>